package com.xinqi.modules.prepare.prepare.controller.inner;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareQueryDTO;
import com.xinqi.modules.prepare.prepare.dto.rsp.PrepareResultDTO;
import com.xinqi.modules.prepare.prepare.service.PrepareService;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 备课区内部控制层
 *
 * @author: system
 * @date: 2023/03/19
 */
@Hidden
@RestController
@RequestMapping("/inner/prepare")
@RequiredArgsConstructor
public class PrepareInnerController {
    private final PrepareService prepareService;

    /**
     * 备课区-分页
     */
    @GetMapping("/page")
    public R<PageInfo<PrepareResultDTO>> page(Param pageable, PrepareQueryDTO dto) {
        PageInfo<PrepareResultDTO> page = prepareService.page(pageable, dto);
        return R.data(page);
    }

    /**
     * 备课区-详情
     */
    @GetMapping("/{id}")
    public R<PrepareResultDTO> findById(@PathVariable("id") Long id) {
        PrepareResultDTO dto = prepareService.findById(id);
        return R.data(dto);
    }

    /**
     * 备课区-详情
     */
    @GetMapping("/create/default/{userId}")
    public R<String> createDefault(@PathVariable("userId") Long userId) {
        if (prepareService.insertDefault(userId) > 0) {
            return R.ok("创建默认备课区成功");
        } else {
            return R.fail("创建默认备课区成功");
        }
    }
}
